#!/bin/sh

HOSTS="/tmp/dnsd.conf"

cp /etc/dnsd-ap.conf "$HOSTS"

hostname=$(hostname)
if ! grep -q $hostname "$HOSTS" >/dev/null; then
	echo "$hostname.local $(hostname -i)" >> "$HOSTS"
fi

dumpleases -f /run/udhcpd_ap.leases -d | grep -v "^Mac Address" | while read line; do
	ip=$(echo $line | cut -s -F 2)
	hostname=$(echo $line | cut -s -F 3)
	if [ " " != "${line:34:1}" ]; then
		echo "$hostname.local $ip" >> "$HOSTS"
	fi
done

exit 0
